using Test
using FLEXINVERT

@testset "Settings parsing" begin
    tmpf = tempname()*".cfg"
    open(tmpf, "w") do io
        println(io, "spec: co2")
        println(io, "method: congrad")
        println(io, "w_edge_lon: -10.0")
        println(io, "s_edge_lat:  50.0")
        println(io, "e_edge_lon:  10.0")
        println(io, "n_edge_lat:  60.0")
        println(io, "xres: 1.0")
        println(io, "yres: 1.0")
        println(io, "regions: false")
    end
    cfg = read_config_settings(tmpf)
    @test cfg.spec == "co2"
    @test cfg.method == "congrad"
    @test cfg.w_edge_lon == -10.0
    rm(tmpf; force=true)
end

@testset "Regions (no aggregation)" begin
    cfg = FLEXINVERT.Settings.Config(; w_edge_lon=-10.0, s_edge_lat=50.0, e_edge_lon=10.0, n_edge_lat=60.0,
                                      xres=1.0, yres=1.0, regions=false, inc_ocean=false)
    dom = FLEXINVERT.CoreTypes.Domain(cfg)
    files = FLEXINVERT.Settings.Files()
    FLEXINVERT.Regions.get_regions!(dom, files, cfg)
    @test dom.nxregrid == 20
    @test dom.nyregrid == 10
    @test dom.nbox == 200
    @test length(dom.hloc) == dom.nbox
end

# Include footprint tests
include("test_footprints.jl")

# Include observation tests
include("test_observations.jl")

# Include transport tests
include("test_transport.jl")

# Allow developers to opt-in to heavier forward-model and covariance suites by setting
# `FLEXINVERT_ENABLE_FULL_TESTS=1`. The default run keeps the fast parity/fixture checks so
# CI can execute without the full FLEXPART inputs.
const RUN_FULL_TESTS = get(ENV, "FLEXINVERT_ENABLE_FULL_TESTS", "0") in ("1", "true", "yes")

if RUN_FULL_TESTS
    include("test_forward_model.jl")
    include("test_covariance.jl")
    include("test_transform_parity.jl")
    include("test_optimization.jl")
    include("test_integration.jl")
    include("test_mcmc.jl")
else
    @info "Skipping forward model, covariance, parity, optimization, integration, and MCMC suites (set FLEXINVERT_ENABLE_FULL_TESTS=1 to enable)"
end
